﻿using System;
using System.Collections.Generic;
using System.Linq;
using InvestmentIntelligence.DbModel.Models;
using Security = InvestmentIntelligence.DbModel.Models.Security;

namespace InvestmentIntelligence.Data.Repository
{
    public interface ISecurityUpdatableRepository : ISecurityRepository
    {
        /// <summary>
        ///     Save Securities in DataBase,
        /// </summary>
        /// <param name="securitylist">List of Security</param>
        /// <param name="keyComparer">Compare Natural Key for given securities. Used for adding new items</param>
        /// <param name="fullComparer">Compare all Secutity fields. Used for modifying items</param>
        void Save(IEnumerable<Security> securitylist, IEqualityComparer<Security> keyComparer = null, IEqualityComparer<Security> fullComparer = null);

        /// <summary>
        ///     Save List Security Models using bulk insert
        /// </summary>
        /// <param name="list"></param>
        void BulkInsert(IEnumerable<Security> list);

        void Add(IEnumerable<Security> security);

        /// <summary>
        ///     Use it to call stored procedure to update parent id
        /// </summary>
        //void UpdateParrentId();

        void Update(IEnumerable<Security> existingSecurities);

        int Add(Security security);
        void Merge(IEnumerable<Security> toList);
    }

    public interface ISecurityRepository
    {
        /// <summary>
        ///     Return list of securities
        /// </summary>
        /// <returns></returns>
        List<T> GetList<T>(Func<IQueryable<Security>, IEnumerable<T>> f);

        /// <summary>
        ///     Return list of securities, filter by EconomicSectorId
        /// </summary>
        /// <param name="id">EconomicSector Id</param>
        /// <returns></returns>
        List<T> GetListByEconomicSectorId<T>(Func<IQueryable<Security>, IEnumerable<T>> f, int id);

        /// <summary>
        ///     Return list of securities, filter by CountryId
        /// </summary>
        /// <param name="id">CountryId</param>
        /// <returns></returns>
        List<T> GetListByCountryId<T>(Func<IQueryable<Security>, IEnumerable<T>> f, int id);

      
        /// <summary>
        ///     Return by Id
        /// </summary>
        /// <param name="id"> security id</param>
        /// <returns></returns>
        Security Get(int id);

        /// <summary>
        ///     Return by Ids
        /// </summary>
        /// <param name="ids"> security ids</param>
        /// <returns></returns>
        List<T> Get<T>(Func<IQueryable<Security>, IEnumerable<T>> f, IEnumerable<int> ids);

        List<Security> GetList();


        List<SecurityView> GetTreeSecuritiesByText(string term, int limit, string filter=null);

        /// <summary>
        /// Return securities tree structures for given securities ids.
        /// </summary>
        /// <param name="securityIds"></param>
        /// <returns></returns>
        List<SecurityView> GetTreeSecurities(IEnumerable<int> securityIds);

        List<SecurityView> FindBy(string term, string field);
    }
}